<template>
    <div >
      <zh-card title="">
      <zh-form :model="state.queryParams" ref="queryFormRef" label-width="150px">
        
        <zh-form-input prop="fileClassCode" label="文件分类编码"  v-model="state.queryParams.fileClassCode" :span="8"
                       :disabled="false"></zh-form-input>
                       
        <zh-form-input prop="classTitle" label="分类标题"  v-model="state.queryParams.classTitle" :span="8"
                       :disabled="false"></zh-form-input>
        <zh-form-select
            prop="appId"
            :lazy="true"
            label="所属应用"
            :span="8"
            v-model="state.queryParams.appId"
            :fieldNames="{ label: 'appName', value: 'appId' }"
            funcCode="application0012"
            :disabled="false"
            searchField="appName"
        ></zh-form-select>
      
        <zh-form-input type="date" prop="expireTimeStartq" label="开始到期时间"  v-model="state.queryParams.expireTimeStartq" :span="8"
                       :disabled="false"></zh-form-input>
        <zh-form-input type="date" prop="expireTimeEndq" label="结束到期时间"  v-model="state.queryParams.expireTimeEndq" :span="8"
                       :disabled="false"></zh-form-input>   
        <zh-form-select prop="authStatus" label="审核状态"  allowClear :span="8" :fieldNames="{label: 'dictValue', value: 'dictKey'}" 
              :options="state.dictData.AUTHSTATUS"  v-model="state.queryParams.authStatus"></zh-form-select>            
        <zh-form-query v-model="state.advanced" @queryClick="queryfileAppRead" :formRef="queryFormRef"></zh-form-query>
      </zh-form>
    
      </zh-card>
      <div >
        <zh-row>
            <zh-col :span="12">
                <zh-table title="文件应用读取授权" ref="fileAppReadTable" size="mini"  :url="VITE_FILE_API_URL+'fileAppRead0001'"

                    :columns="state.tableColumns" highlight-current-row>    
                    <template #op="scope">
                        <el-tooltip content="授权审核" placement="top">
                            <el-button :icon="Edit" link @click="authRead(scope.row)"></el-button>
                        </el-tooltip>
                    </template>
                </zh-table>
            </zh-col>

            <zh-col :span="12">
                <zh-table title="文件应用分类存储授权" ref="fileAppClassTable" size="mini"  :url="VITE_FILE_API_URL+'fileAppRead0007'"
                    :columns="state.tableColumns2" highlight-current-row>  
                    <template #op="scope">
                        <el-tooltip content="授权审核" placement="top">
                            <el-button :icon="Edit" link @click="authWrite(scope.row)"></el-button>
                        </el-tooltip>
                    </template>
                </zh-table>
            </zh-col>
        </zh-row>
    </div>
      

        <zh-dialog style="width:30%" title="文件应用读取授权审核" v-model="state.authVerifyReadVisible">
            <AuthVerifyRead  ref="authVerifyReadPage" :AuthVerifyReadParam="state.selectRow" v-model="state.authVerifyReadVisible"></AuthVerifyRead>
            <template #footer>
                <span class="dialog-footer">
                    <zh-button @click="state.authVerifyReadVisible = false">取消</zh-button>
                    <zh-button v-if="!state.showFlag" type="primary" @click="saveAuthRead">
                        审核通过
                    </zh-button>
                    <zh-button v-if="!state.showFlag" type="primary" @click="saveAuthReadNo">
                        审核不通过
                    </zh-button>
                </span>
            </template>
        </zh-dialog>
        <zh-dialog style="width:30%" title="文件应用存储授权审核" v-model="state.authVerifyWriteVisible">
            <AuthVerifyWrite  ref="authVerifyWritePage" :AuthVerifyWriteParam="state.selectRowWrite" v-model="state.authVerifyWriteVisible"></AuthVerifyWrite>
            <template #footer>
                <span class="dialog-footer">
                    <zh-button @click="state.authVerifyWriteVisible = false">取消</zh-button>
                    <zh-button v-if="!state.showFlag" type="primary" @click="saveAuthWrite">
                        审核通过
                    </zh-button>
                    <zh-button v-if="!state.showFlag" type="primary" @click="saveAuthWriteNo">
                        审核不通过
                    </zh-button>
                </span>
            </template>
        </zh-dialog>
       
    </div>
</template>

<script lang="ts" setup name="fileApplyIndex">
import {  Edit } from '@element-plus/icons-vue'
import AuthVerifyRead from '@/views/fileCenter/fileEnpower/component/AuthVerifyRead.vue';
import AuthVerifyWrite from '@/views/fileCenter/fileEnpower/component/AuthVerifyWrite.vue';
const VITE_FILE_API_URL = import.meta.env.VITE_FILE_API_URL as string+'/doc/api/';


const queryFormRef = ref();
const fileAppReadTable = ref();
const fileAppClassTable = ref();
const authVerifyReadPage = ref();
const authVerifyWritePage = ref();


const state = reactive({
    authVerifyReadVisible:false,
    authVerifyWriteVisible:false,
    selectRow:{},
    selectRowWrite:{},
    advanced: false,
    showFlag:false,
    queryParams: {
        fileClassCode:'',
        classTitle:'',
        appId:'',
        permitAppId:'',
        expireTime:'',
        expireTimeStart:0,
        expireTimeEnd:0,
        expireTimeStartq:'',
        expireTimeEndq:'',
        authStatus:'0',
    },
    dictFields: 'AUTHSTATUS',
    dictData: {} as any,
    tableColumns: [
        { type: 'seq', width: 60, fixed: 'left', align: 'center', title: '序号' },
        { field: 'appReadId', title: 'appReadId', visible: false, fixed: 'left',align: 'center', width: 120 },
        { field: 'fileClassCode', title: '文件分类编号', visible: true, fixed: 'left',align: 'center', width: 120 },
        { field: 'classTitle', title: '文件分类标题', visible: true, fixed: 'left',align: 'center', width: 120 },
        { field: 'appId', title: '应用ID', visible: false, fixed: 'left',align: 'center', width: 120 },
        { field: 'appName', title: '应用名称', visible: true, fixed: 'left',align: 'center', width: 120 },
        { field: 'secrecyLevel', title: '保密级别ID', visible: false, fixed: 'left',align: 'center', width: 120 },
        { field: 'secrecyLevelName', title: '保密级别', visible: true, fixed: 'left',align: 'center', width: 120 },
        { field: 'expireTime', title: '过期时间',type:'Date', visible: true, fixed: 'left',align: 'center', width: 120 },
        { field: 'authStatus', title: '审核状态', visible: false, fixed: 'left',align: 'center', width: 120 },
        { field: 'authStatusName', title: '审核状态', visible: true, fixed: 'left',align: 'center', width: 120 },
        {
            field: 'op',
            title: '操作',
            visible: true,
            align: 'center',
            width: 70,
            fixed: 'right',
            slots: { default: 'op' }
        },
    ],
    tableColumns2: [
        { type: 'seq', width: 60, fixed: 'left', align: 'center', title: '序号' },
        { field: 'appClassId', title: 'appClassId', visible: false, fixed: 'left',align: 'center', width: 120 },
        { field: 'fileClassCode', title: '文件分类编号', visible: true, fixed: 'left',align: 'center', width: 120 },
        { field: 'fileClassTitle', title: '文件分类标题', visible: true, fixed: 'left',align: 'center', width: 120 },
        { field: 'appId', title: '应用ID', visible: false, fixed: 'left',align: 'center', width: 120 },
        { field: 'appName', title: '应用名称', visible: true, fixed: 'left',align: 'center', width: 120 },
        { field: 'fileClassPath', title: '文件存放路径', visible: true, fixed: 'left',align: 'center', width: 120 },
        { field: 'expireTime', title: '过期时间',type:'Date', visible: true, fixed: 'left',align: 'center', width: 120 },
        { field: 'authStatus', title: '审核状态', visible: false, fixed: 'left',align: 'center', width: 120 },
        { field: 'authStatusName', title: '审核状态', visible: true, fixed: 'left',align: 'center', width: 120 },
        {
            field: 'op',
            title: '操作',
            visible: true,
            align: 'center',
            width: 70,
            fixed: 'right',
            slots: { default: 'op' }
        },
    ],


});

//------------------初始化------------------------------
onMounted(() => {
    getDict();
})
//--------------------------定义调用方法--------------------------------------------------
function getDict() {
    setTimeout(() => {
        let params = {
            dictFields: state.dictFields,
        };
        $api.common.getBatchDict.post(params).then((res: any) => {
            state.dictData = res.result;
        });

    }, 20);
}

 const queryfileAppRead = () => {
    let dateStr = state.queryParams.expireTimeStartq;
    var date=new Date(dateStr);
    state.queryParams.expireTimeStart= date.getTime();

    let dateStr2 = state.queryParams.expireTimeEndq;
    var date2=new Date(dateStr2);
    state.queryParams.expireTimeEnd= date2.getTime();

    //查询读取权限
    fileAppReadTable.value.query(state.queryParams);
    // 查询保存权限
    fileAppClassTable.value.query(state.queryParams);
 }

 
 const authRead = (row) => {   
    if(row.authStatus==='0'){
        state.showFlag = false;
    }else{
        //已审核数据，隐藏审核按钮
        state.showFlag = true;
    }
    
    if(row.fileClassCode){
        state.authVerifyReadVisible=true;        
        state.selectRow = row;
    }else{
        $messageBox.warning('请先选择列表信息', '提示');
        return false
    }
 }

 //保存文件读取授权审核数据
function saveAuthRead(){  
    authVerifyReadPage.value.savePass().then(()=>{
        queryfileAppRead();
    })
}

function saveAuthReadNo(){
    authVerifyReadPage.value.saveNoPass().then(()=>{
        queryfileAppRead();
    })
} 

 const authWrite = (row) => {
    if(row.authStatus==='0'){
        state.showFlag = false;
    }else{
        //已审核数据，隐藏审核按钮
        state.showFlag = true;
    }
    
    if(row.fileClassCode){
        state.authVerifyWriteVisible=true;        
        state.selectRowWrite = row;
    }else{
        $messageBox.warning('请先选择列表信息', '提示');
        return false
    }
}

 //保存文件存储授权审核数据
 function saveAuthWrite(){  
    authVerifyWritePage.value.savePass().then(()=>{
        queryfileAppRead();
    })
}

function saveAuthWriteNo(){
    authVerifyWritePage.value.saveNoPass().then(()=>{
        queryfileAppRead();
    })
} 

</script>
